# encoding: utf-8
# @author: wangxin
# @software: garner
# @file: getSetmealReportViews.py
# @time: 2025/1/22 9:31
import pymysql
from django.db.models.expressions import result
from django.views import View
import json
from tabnanny import check

# 导入Django核心模块中的序列化器，用于将Django模型转换为其他格式，如JSON、XML等
from django.core import serializers

# 导入Django序列化功能，以便在需要时将模型序列化
from django.core.serializers import serialize
from django.db.models import Q

# 导入HttpResponse和JsonResponse类，用于构建HTTP响应和JSON响应
from django.http import HttpResponse, JsonResponse

# 导入render函数，它用于根据请求和模板渲染网页
from django.shortcuts import render

from django.views import View
# 导入分页类
from django.core.paginator import Paginator
class getSetmealReportViewsView(View):
    def get(self,request):
        conn = pymysql.Connect(
            host="127.0.0.1",
            port=3306, user="root",
            password="123456",
            db="ruici",
            charset="utf8",
            autocommit=True
        )
        cursor = conn.cursor()
        sql = f"SELECT o.setmeal_id, s.NAME FROM t_order as o INNER JOIN t_setmeal as s ON o.setmeal_id = s.id GROUP BY o.setmeal_id, s.NAME;"
        cursor.execute(sql)
        res= cursor.fetchall()

        data_list= list()
        for data in res:
            data_dict = dict()
            data_dict['value'] = data[0]
            data_dict['name'] = data[1]
            data_list.append(data_dict)

        result = {
            "status": "200",
            "data": data_list

        }
        return JsonResponse(result)